package com.qf.qflivehou.controller;

import com.qf.qflivehou.mapper.repository.CodeRepository;
import com.qf.qflivehou.pojo.reqVo.UserReq;
import com.qf.qflivehou.pojo.respVo.ResponseData;
import com.qf.qflivehou.service.UserService;
import com.qf.qflivehou.utils.EmailUtils;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.Liu
 * @date 2022/1/10 17:22
 */

/**
 * 用户处理层
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 校验邮箱是否重复
     * @param email
     * @return
     */
    @PostMapping("/validataEmail")
    public ResponseData validataEmail(@RequestParam("email") String email) {
        ResponseData responseData = userService.findEmail(email);
        return responseData;
    }

    /**
     * 校验用户名是否重复
     * @param userReq
     * @return
     */
    @PostMapping("/validataloginName")
    public ResponseData validataloginName(@RequestBody UserReq userReq){
        ResponseData responseData = userService.validataloginName(userReq);
        return responseData;
    }

    @RequestMapping("/getCode")
    public ResponseData getCode(@RequestParam("email")String email){
        ResponseData responseData = userService.getCode(email);
        return responseData;
    }

    @PostMapping("/registry")
    public ResponseData registry(@RequestBody UserReq userReq){
        ResponseData responseData = userService.registry(userReq);
        return responseData;
    }

    @PostMapping("/login")
    public ResponseData login(@RequestBody UserReq userReq){
        ResponseData responseData = userService.login(userReq);
        return responseData;
    }

    @PostMapping("/findUserByToken")
    public ResponseData findUserByToken(HttpServletRequest request){
        ResponseData responseData = userService.findUserByToken(request);
        return responseData;
    }
}
